import {connect, useNavigate} from "umi";
import CheckListWithSearch from "@/components/CheckListWithSearch";

const FeeDeptPage = ({dispatch, feeDept}) => {
    const navigate = useNavigate();

    const handleCheck = (value) => {
        console.log(value)
        if (value) {
            const feeDept = value[0];
            navigate("/", {
                state: {
                    feeDept: {
                        id: feeDept.id,
                        name: feeDept.name,
                        code: feeDept.code
                    },
                }
            })
        }

    }

    const handleSearch = (v) => {
        dispatch({
            type: 'feeDept/setSearchText',
            payload: {
                value: v
            }
        });
    }


    return (
        <CheckListWithSearch data={feeDept.list} searchText={feeDept.searchText} onCheck={v => handleCheck(v)}
                             onSearch={v => handleSearch(v)}/>
    );

};

export default connect(feeDept => feeDept)(FeeDeptPage);
